﻿@model QuanLyGiaoVuUI.Models.GiangVienClient.DanhSachLichThiViewModel
@{
    Layout = "~/Views/Shared/_GiangVienClientLayout.cshtml";
}

<style>
    .hidden {
        display: none;
    }
</style>

<div id="gv-main-wrapper">
    @{ Html.RenderPartial("GiangVienClientGiangDayMenuPartial");}

    <div id="main" class="grid_10">
        <!--  start page-heading -->

        <div id="page-heading" class="box round first grid">
            <h2>Danh sách đăng ký lịch thi</h2>
            <!-- end page-heading -->
            <div class="block">
                <table class="data display datatable">
                    <tr>
                        <th class="sorting"></th>
                        <th class="sorting">Mã lớp
                        </th>
                        <th class="sorting">Tên Môn học
                        </th>
                        @*                    <th>
                        Sĩ số
                    </th>*@
                        <th class="sorting">Loại lớp
                        </th>
                        <th class="sorting">Khóa
                        </th>
                        <th class="sorting">Tùy chọn
                        </th>
                    </tr>
                    @{int count = 0;}
                    @foreach (var item in Model.DanhSachLopMonHoc)
                    {
                        <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                            <td>
                                <a href="javascript:;" class="btnToggle"><img src="~/Images/toggle_plus.png" class="btnPlus"/><img src="~/Images/toggle_minus.png" class="btnMinus"/></a>
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.MaLopDayDu)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.MonHoc.TenMonHoc)
                            </td>
                            <td>
                                @(item.LoaiLop == 0 ? "Lý Thuyết" : "Thực Hành")
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.LopSinhVien.TenLop)
                            </td>
                            <td>
                                <a href="#" onclick="DangKyLichThi('@item.LopMonHocId')">Đăng ký lịch thi</a>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td colspan="5">
                                <table style="width: 100%" class="data display datatable">
                                    <tr>
                                        <th class="sorting">Ngày thi
                                        </th>
                                        <th class="sorting">Giờ thi
                                        </th>
                                        <th class="sorting">Hình thức thi
                                        </th>
                                        <th class="sorting">
                                            Tùy chọn
                                        </th>
                                    </tr>
                                    @{ int subCount = 0;}
                                    @foreach (QuanLyGiaoVuDAL.DTO.LichThiDTO lichThi in item.DanhSachLichThi)
                                    {
                                        <tr class="gradeA @(++subCount % 2 == 0 ? "even" : "odd")">
                                        <td>@lichThi.NgayGio.ToShortDateString()
                                        </td>
                                            @{
                                        var fromHour = lichThi.NgayGio.Hour < 10 ? "0" + lichThi.NgayGio.Hour.ToString() : lichThi.NgayGio.Hour.ToString();
                                        var fromMinute = lichThi.NgayGio.Minute < 10 ? "0" + lichThi.NgayGio.Minute.ToString() : lichThi.NgayGio.Minute.ToString();
                                        var toHour = lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Hour < 10 ? "0" + lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Hour.ToString() : lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Hour.ToString();
                                        var toMinute = lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Minute < 10 ? "0" + lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Minute.ToString() : lichThi.NgayGio.AddMinutes(lichThi.ThoiGianLamBai).Minute.ToString();
                                                }
                                        <td>@(fromHour + "h")@(fromMinute + " - " + (toHour + "h") + toMinute)
                                        </td>
                                        <td>@(lichThi.HinhThucThi == 1 ? "Báo cáo" : (lichThi.HinhThucThi == 2 ? "Thực hành" : "Lý thuyết"))
                                        </td>
                                        <td>
                                            <a href="javascript:;" onclick="DangKyLichThi('@item.LopMonHocId','@lichThi.MaLichThi')">Sửa</a>|
                                            <a href="javascript:;" data-id="@lichThi.MaLichThi" class="btnXoaDangKyLichThi">Xóa</a>
                                        </td>
                                    </tr>
                                    }
                                </table>
                            </td>
                        </tr>
                    }
                </table>
            </div>
        </div>
    </div>
</div>
<div id="DangKyLichThiDialog"></div>


<script>
    $(document).ready(function () {
        $(".btnPlus").addClass("hidden");
        $(".btnPlus").bind("click", function () {
            var tableRow = $(this).closest("tr").next();
            if (tableRow.hasClass("hidden"))
                tableRow.removeClass("hidden");
            $(this).parent().find(".btnMinus").removeClass("hidden");
            $(this).addClass("hidden");
        });
        $(".btnMinus").bind("click", function () {
            var tableRow = $(this).closest("tr").next();
            if (!tableRow.hasClass("hidden"))
                tableRow.addClass("hidden");
            $(this).parent().find(".btnPlus").removeClass("hidden");
            $(this).addClass("hidden");
        });
        $(".btnXoaDangKyLichThi").bind("click", function () {
            var id = $(this).data("id");
            var currentRow = $(this).closest("tr");
            if (confirm("Xóa thông tin đăng ký thi này?")) {
                $.ajax({
                    type: "post",
                    url: "/LopMonHoc/XoaDangKyLichThi",
                    data: {
                        maDangKyLichThi: id
                    },
                    success: function (data) {
                        if (data.success) {
                            ToastManager.showSuccessToast(data.message);
                            currentRow.remove();
                        }
                        else
                            ToastManager.showStickyWarningToast(data.message);
                    }
                });
            }
        });
    });

    function DangKyLichThi(maLopMonHoc, maLichThi) {
        var url = "/GiangVienClient/DangKyLichThi?maLopMonHoc=" + maLopMonHoc;
        if (maLichThi)
        {
            url = url + "&maLichThi=" + maLichThi;
        }
        $("#DangKyLichThiDialog").load(url, function () {
            $("#NgayThi").datepicker();
            $("#GioThi").timepicker();
            $("#GioKetThuc").timepicker();
            $("#DangKyLichThiDialog").dialog({
                width: 400,
                title: "Đăng ký ngày thi",
                height: 'auto',
                buttons: {
                    "Đăng ký": function () {
                        $("#dangKyLichThi-submit").click();
                    },
                    "Hủy": function () {
                        $("#DangKyLichThiDialog").dialog("close");
                    }
                }
            });
        });
    }
</script>
